define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trades/assets/ordrelact/index' + location.search,
                    // add_url: 'trades/assets/ordrelact/add',
                    // edit_url: 'trades/assets/ordrelact/edit',
                    // del_url: 'trades/assets/ordrelact/del',
                    // multi_url: 'trades/assets/ordrelact/multi',
                    // import_url: 'trades/assets/ordrelact/import',
                    table: 'activity_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                       // {checkbox: true},
                        {field: 'orderid', title: __('Orderid')},
                       // {field: 'buyer_id', title: __('Buyer_id')},
                        {field: 'amount', title: __('Amount'),operate:false},
                        {field: 'paytype_text', title: __('Paytype'), operate: false,formatter:function(value,row){
                                if (row['paytype'] == 1)
                                {
                                    return '<span style="color:yellowgreen">'+value+'</span>';
                                }else {
                                    return '<span style="color:black">'+value+'</span>';
                                }
                            }
                        },
                        {field: 'paytime', title: __('Paytime'), operate: 'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createTime', title: __('Createtime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'ordertype_text', title: __('Ordertype'), operate: false,formatter:function(value,row){
                                if (row['ordertype'] == 1)
                                {
                                    return '<span style="color:yellowgreen">'+value+'</span>';
                                }else {
                                    return '<span style="color:black">'+value+'</span>';
                                }
                            }
                        },
                        //{field: 'isend', title: __('Isend')},
                        // {field: 'activity.id', title: __('Activity.id')},
                        {field: 'activity.name', title: __('Activity.name'),  align: 'left', operate: 'LIKE %...%', placeholder: '模糊搜索,*表示任意字符'},
                        // {field: 'activity.serial', title: __('Activity.serial')},
                        // {field: 'activity.thumb', title: __('Activity.thumb'), operate: 'LIKE'},
                        // {field: 'activity.summary', title: __('Activity.summary'), operate: 'LIKE'},
                        // {field: 'activity.createTime', title: __('Activity.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'activity.startTime', title: __('Activity.starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'activity.duration', title: __('Activity.duration')},
                        // {field: 'activity.category', title: __('Activity.category')},
                        // {field: 'activity.tags', title: __('Activity.tags'), operate: 'LIKE'},
                        // {field: 'activity.isrecording', title: __('Activity.isrecording')},
                        // {field: 'activity.series_id', title: __('Activity.series_id')},
                        // {field: 'activity.admin_id', title: __('Activity.admin_id')},
                        // {field: 'activity.status', title: __('Activity.status')},
                        // {field: 'activity.collection', title: __('Activity.collection'), operate: 'LIKE'},
                        // {field: 'activity.share', title: __('Activity.share'), operate: 'LIKE'},
                        // {field: 'activity.operate_id', title: __('Activity.operate_id')},
                        // {field: 'activity.delTime', title: __('Activity.deltime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'activity.endTime', title: __('Activity.endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                       // {field: 'activity.isend', title: __('Activity.isend')},
                        {field: 'activity.isend_text', title: __('Activity.isend'), operate: false,formatter:function(value,row){
                                if (row['Activity.isend'] == 1)
                                {
                                    return '<span style="color:yellowgreen">'+value+'</span>';
                                }else {
                                    return '<span style="color:black">'+value+'</span>';
                                }
                            }
                        },
                        {
                            field: 'activity.isend',
                            title: __('Activity.isend'),
                            visible:false,
                            formatter: Table.api.formatter.normal,
                            searchList: { '0': '否','1': '是'},

                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '详情',
                                    icon: 'fa fa-folder-o',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'trades/assets/ordrelact/detail?ids={ids}',
                                },
                            ],
                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});